<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\validate\serial\Log;
use think\Db;
use EasyWeChat\Factory;
use think\Session;

/**
 * 活动领取
 */
class Contract extends Api
{

    //如果$noNeedLogin为空表示所有接口都需要登录才能请求
    //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
    //如果接口已经设置无需登录,那也就无需鉴权了
    //
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['*'];
  
    protected $noNeedRight = ['*'];
    protected $model;

    public  $app = null;


    public function _initialize(){
        $this->model = new \app\admin\model\shop\Contract;
         $this->Serialmodel = new \app\common\model\Serial;
         $this->ModelShop = Db::connect([
            // 数据库类型
            'type'        => 'mysql',
            // 服务器地址
            'hostname'    => '42.96.177.38',
            // 数据库名
            'database'    => 'tf2020',
            // 数据库用户名
            'username'    => 'wangmeng',
            // 数据库密码
            'password'    => 'wangmeng',
            // 数据库编码默认采用utf8
            'charset'     => 'utf8',
        ]);
    }

    public function getcontract($ids = null,$userid = null){
            if(!$ids || !$userid)  $this->error('参数错误');
            if(!$row = $this->model->where(['order_id'=>$ids,'userid'=>$userid])->find()){
                $this->error('没有合同');
            }
            if($row['status'] == 1)  $this->error('没有合同');
           $this->success('操作成功',$row['contract_url']);       
       
    }

    public function upcontract(){
         $param = $this->request->post();
         if(!isset($param['order_id'])) return false;
         if($info = $this->ModelShop->table("tf_hetong")->where('order_sn',$param['order_id'])->find()){
            if($info['uid']){
                $this->ModelShop->table("pre_common_member")->where('uid',$info['uid'])->update(['groupid'=>5]);
            }
         }
         $this->Serialmodel->where('order_sn',$param['order_id'])->delete();
         $this->ModelShop->table("tf_hetong")->where('order_sn',$param['order_id'])->delete();
         return true;
    }

}
